package com.hzcc.hzccblog.module.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzcc.hzccblog.common.Result;
import com.hzcc.hzccblog.common.enums.ArticleEnums;
import com.hzcc.hzccblog.module.dao.ArticleImageDao;
import com.hzcc.hzccblog.module.entity.po.ArticleImage;
import com.hzcc.hzccblog.module.service.ArticleImageService;
import com.hzcc.hzccblog.utils.FileUpdateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @Author 早睡蛋
 * @Date 2022/6/12 15:17:17
 * @Desc:
 */
@Service
public class ArticleImageServiceImpl extends ServiceImpl<ArticleImageDao, ArticleImage> implements ArticleImageService {

    @Autowired
    private ArticleImageDao articleImageDao;

    @Override
    public Result addArticleImage(MultipartFile file, ArticleImage articleImage,String articleImages) {
        FileUpdateUtil fileUpdateUtil = new FileUpdateUtil();
        Map<String,String> map = fileUpdateUtil.updateArticlePic(file,articleImages);
        String dataPath = map.get("dataPath");
        articleImage.setPath(dataPath);
        int flag = articleImageDao.insert(articleImage);
        if (flag>0){
            return ArticleEnums.OK.getResult().setData(map);
        }else {
            return ArticleEnums.FAIL.getResult();
        }
    }
}
